$(function(){
// var id = 1300;
var step = $('#getStep').val();
var nowp =$('#nowp').val();
    if(nowp==false || nowp==1){
        setInterval(getTr(step),8000);
    }
});
function getTr(step){

var id = $('#nowId').val();
    // var id = 2244;
var start_time = $('#datemin').val();
var end_time = $('#datemax').val();
var key = $('.searchKey').val();
var step = $("#getStep").val();;
var phone_order = $("#phone_order").val();;
var community_id = $(".community_id option:selected").val();
var selectType = $(".selectType option:selected").val();
var lxurl = $.getEnvUrl();
// console.log(key);
           $.ajax({
        url: lxurl+"?m=Service&c=WxOrder&a=roll",
               type: "POST",
               data:{
                   start_time:start_time,
                   end_time:end_time,
                   community_id:community_id,
                   selectType:selectType,
                   key:key,
                   step:step,
                   id:id,
                   phone_order:phone_order,
               },

        error: function () {

        },
        success: function (data, status) { 
            console.log(data);
            if (data.status == false) {
               
            } else {
                
                for (var i = 0; i < data.data.length; i++) {
                    if(data.data[i].is_repair==1)
                       var red = "style='color:red'";
                   else
                    var red = "";

                    if(data.data[i].handler_name==null)
                       var handler_name = "";
                   else
                    var handler_name = data.data[i].handler_name;

                    if(data.data[i].handler_mobile==null)
                       var handler_mobile = "";
                   else
                    var handler_mobile = data.data[i].handler_mobile;

                    if(data.data[i].service_name==null)
                       var service_name = "";
                   else
                    var service_name = data.data[i].is_repair;

                    if(data.data[i].rob_start_time==0)
                       var rob_start_time = "";
                   else
                    var rob_start_time = data.data[i].is_repair;

                    if(data.data[i].type==1)
                       var orderType = "家庭维修";
                   else if(data.data[i].type==2)
                    var orderType = '公共维修';

                var str = "<tr  class='text-c' class='odd' role='row'>";
                 str += "<td width='40'>"+data.data[i].serialno+"</td>";
                 if (data.data[i].step_title == '未受理' || data.data[i].step_title == '无人抢单'){
                  str += "<td style='color: #eb5b43'>"+data.data[i].step_title+"</td>";   
                 }else if(data.data[i].step_title == '价格确认完毕' || data.data[i].step_title == '开始维修' || data.data[i].step_title == '价格确认中' || data.data[i].step_title == '等待审核'){
                    str += "<td style='color: #2075b6'>"+data.data[i].step_title+"</td>";
                 }else if(data.data[i].step_title == '已取消'){
                    str += "<td width='180' style='color: #843f08'>"+data.data[i].step_title+"</td>";
                 }else if(data.data[i].step_title == '订单完成' || data.data[i].step_title == '完成维修'){
                    str += "<td width='180' style='color: #159b61'>"+data.data[i].step_title+"</td>";
                 }else if(data.data[i].step_title == '抢单中'){
                    str += "<td width='180' style='color: #178483'>"+data.data[i].step_title+"</td>";
                 }else if(data.data[i].step_title == '已评价'){
                    str += "<td width='180' style='color: #992aef'>"+data.data[i].step_title+"</td>";
                 }
                 // str += "<td width='180'>"+data.data[i].step_title+"</td>";
                 str += "<td width='180'>"+orderType+"</td>";
                 str += "<td width='160'>"+data.data[i].entry_name+"</td>";
                 str += "<td width='800'>"+data.data[i].info+"</td>";
                 str += "<td width='100'>"+data.data[i].community_name+"</td>";
                 // str += "<td width='200'>"+data.data[i].customer.realname+"</td>";
                 str += "<td width='140'><span "+red+"title='"+data.data[i].customer.tel+"'>"+data.data[i].customer.realname+"</span></td>";
                 // str += "<td width='80'>"+data.data[i].customer.tel+"</td>";
                 str += "<td width='120'>"+data.data[i].address+"</td>";
                 str += "<td width='100'>"+data.data[i].create_time+"</td>";
                 str += "<td width='180'>"+rob_start_time+"</td>";
                 str += "<td width='160'><span title='"+handler_mobile+"'>"+handler_name+"</td>";
                 // str += "<td width='220'>"+handler_mobile+"</td>";
                 str += "<td width='180'>"+service_name+"</td>";
                 str += "<td width='180'>"+data.data[i].price+"</td>";
                 var orderManage = $('#orderManage').val();
                 if(data.data[i].has_repair!=null && data.data[i].is_edit==1){

                    str += "<td width='80'><a href='/index.php?m=Service&c=WxOrder&a=rob&id="+data.data[i].id+"' class='label label-secondary  radius ' onclick='return confirm("+"&#39;是否设为自助抢单&#39;"+")'>自助抢单</a>";
                 }else{
                    str += "<td width='80'><a class='label radius ' style='cursor: not-allowed;'>自助抢单</a>";
                 }
                 if (data.data[i].is_edit==1 || orderManage==true) {
                    str += "<a href='javascript:to2("+"&#39;/index.php?m=Service&c=WxOrder&a=appoint&id="+data.data[i].id+"&#39;"+");' class='label label-secondary  radius '>人工指派</a>";
                    str += "<a href='javascript:to3("+"&#39;/index.php?m=Service&c=WxOrder&a=cancel&id="+data.data[i].id+"&#39;"+");' class='label label-secondary  radius '>取消订单</a>";
                    str += "<a href='javascript:to2("+"&#39;/index.php?m=Service&c=WxOrder&a=info&id="+data.data[i].id+"&#39;"+");' class='label label-secondary  radius '>查看详情</a>";
                    str += "<a href='/index.php?m=Service&c=WxOrder&a=done&id="+data.data[i].id+"' class='label label-secondary  radius' onclick='return confirm(&#39;确定完成该订单？&#39;);'>直接完成</a>";

                 }else if(data.data[i].is_edit==-1){
                    str += "<a class='label radius ' style='cursor: not-allowed;'>人工指派</a>";
                    str += "<a class='label radius ' style='cursor: not-allowed;'>取消订单</a>";
                    str += "<a href='javascript:to2("+"&#39;/index.php?m=Service&c=WxOrder&a=info&id="+data.data[i].id+"&#39;"+");' class='label label-secondary  radius'>查看详情</a>";
                 }
                if(orderManage==true)
                  str += "<a href='/index.php?m=Service&c=WxOrder&a=delete&id="+data.data[i].id+"' class='label label-secondary  radius' onclick='return confirm(&#39;确定删除该订单？&#39;);' id='order_deltete'>删除订单"; 
                
                str += "</td></tr>";

                
                
                $("#roll").after(str);
                $("#nowId").val(data.data[i].id);
                }
            }
            setTimeout(function() {
                getTr();
            }, 2000);
        }
    });
}

